package Day03;

import java.util.*;

public class Day03findRepeatNumber {

    public static int findRepeatNumber(int[] nums) {
        HashSet<Integer> flag = new HashSet<>();
        for (int i = 0 ;i<nums.length;i++){
            if(flag.contains(nums[i])){
                return nums[i];
            }else {
                flag.add(nums[i]);
            }
        }
        return -1;
    }
    public static int findRepeatNumber2(int[] nums) {
        int[] arr = new int[nums.length];
        for(int i = 0; i < nums.length; i++){
            arr[nums[i]]++;
            if(arr[nums[i]] > 1) return nums[i];
        }
        return -1;
    }
    public static int studyFindRepeatNumber3(int[] nums){
        int[] flag = new int[nums.length];
        for (int i = 0;i<nums.length;i++){
            flag[nums[i]]++;
            if(flag[nums[i]]>0){
                return nums[i];
            }
        }
        return -1;
    }

}
